package com.syt.mall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

//订单确认页需要用的数据

public class OrderConfirmVo {
    /**
     * 收获地址
     */
    @Setter @Getter
    private List<MemberAddressVo> address;

    /**
     * 所有选中的购物项
     */
    @Setter @Getter
    private List<OrderItemVo> items;


    //发票记录...

    /**
     * 订单防重复令牌
     */
    @Getter @Setter
    private String orderToken;

    /**
     * 优惠券信息
     */
    @Setter @Getter
    private Integer integration;

    @Setter @Getter
    Map<Long,Boolean> stocks;


    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items!=null){
            for (OrderItemVo item : items) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }

        return sum;
    }

    public BigDecimal getPayPrice(){
       return getTotal();
    }

    public Integer getCount(){
        Integer i = 0;
        if(items!= null){
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }
}
